// localStorage.setItem(key, value);

// localStorage.getItem(key);

// localStorage.removeItem(key);
mui.init({
    swipeBack: true //启用右滑关闭功能
});
var info = document.getElementById("info");

$(function() {
    $.ajax({
        url: '/user/logout',
        success: function(res) {
            localStorage.clear('username');
            localStorage.clear('password');
        }
    })
    $('.lgBtn').on('tap', function(e) {
        var userName = $('.userNameIpt').val().trim()
        var passWord = $('.passWordIpt').val().trim()
        if (userName.length <= 0) {
            mui.toast('请输入正确的用户名！');
        } else if (passWord.length <= 0) {
            mui.toast('请输入正确的密码！');
        } else {
            $.ajax({
                url: '/user/login',
                type: 'post',
                data: {
                    username: userName,
                    password: passWord,
                },
                success: function(res) {
                    if (res.success === true) {
                        $('.lgBtn').text('登陆成功')
                        mui.openWindow({
                            url: 'user.html'
                        })
                        $('#my').attr('href', 'user.html')
                        localStorage.setItem('username', userName);
                        localStorage.setItem('password', passWord);
                        $('.mui-badge').css('display', 'block')
                    }
                },
                fail: function(err) {
                    mui.toast(err.message);
                }
            })
        }
        return false
    })
    $('#visible').on('tap', function() {
        if ($('.passWordIpt').attr('type') == 'password') {
            $('.passWordIpt').attr('type', 'text')
            $('#visible').attr('src', './images/invisible.png')
        } else {
            $('.passWordIpt').attr('type', 'password')
            $('#visible').attr('src', './images/visible.png')
        }
    })
})